import{request} from '../../network/index'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		active:0,
		radioBanner:[],
		recommend:[],
		category:[],
		categoryRecommend:[],
		dayRecommend:[],
		hotRedio:[],
		offset:0,
		offset1:0,
		offset2:10,
		pay:[],
		top:[],
		hotToplist:[]
	},
	async onChange(event) {
		let index = event.detail.index
		this.data.active = index
		// 分类数据
		if(index === 2){
			let category = await request('/dj/catelist')
			let categoryRecommend = await request('/dj/category/recommend')
			this.setData({
				category:category.data.categories.slice(0,16),
				categoryRecommend:categoryRecommend.data.data.slice(3)
			})
		//排行榜数据
		}else if(index === 1){
			let hotToplist = await request('/dj/program/toplist',{limit:30,offset:0})
			this.setData({
				top:hotToplist.data.toplist.slice(0,3),
				hotToplist:hotToplist.data.toplist.slice(3)
			})
		}
	},
	async loading(){
		this.data.offset+=3
		let hotRedio = await request('/dj/hot',{limit:3,offset:this.data.offset}) 
		this.setData({
			hotRedio:hotRedio.data.djRadios
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad:async function (options) {
		request('/dj/banner').then(radioBanner => {
			this.setData({
				radioBanner:radioBanner.data.data,
			})
		})
		request('/dj/personalize/recommend').then(recommend => {
			this.setData({
				recommend:recommend.data.data,
			})
		})
		request('/dj/today/perfered').then(dayRecommend => {
			this.setData({
				dayRecommend:dayRecommend.data.data,
			})
		})
		let hotRedio = await request('/dj/hot',{limit:3,offset:this.data.offset}) 
		this.setData({
			hotRedio:hotRedio.data.djRadios
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom:async function () {
		if(this.data.active === 0){
			this.data.offset1+=9
			let pay = await request('/dj/paygift',{limit:9,offset:this.data.offset1})
			this.data.pay.push(...pay.data.data.list)
			this.setData({
				pay:this.data.pay
			})
		}
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})